package main

import (
	"fmt"
)

//无参无返回值function
func method1() {
	a := "method1"
	fmt.Println("method1", a)

	method2("arg1", "arg2", 3.14)
	method3(1, 2)
	method4(1, "a", "b", "c")
	method4(1)
}

//有参无返回 不定参数
func method2(i ...interface{}) {
	for key, value := range i {
		fmt.Println(key, " ", value)
	}
}
func method3(i int, j int) {
	fmt.Println(i + j)
}
func method4(a int, i ...string) {
	fmt.Println("------------------------------")

	fmt.Println(len(i))
	for k := 0; k < len(i); k++ {
		fmt.Println(k, " ", i[k])
	}

	if (len(i) > 2) {
		//不定参数传递截取
		method5(i[2:]...)
		method5(i[:2]...)
	}
}

//多参传递
func method5(k ...string) {
	fmt.Println("------------------------------")
	for _, value := range k {
		fmt.Println(value)
	}
}

//返回一个值
func method6() string {
	return "method6"
}

//返回一个值 常用方法
func method7() (result string) {
	result = "method7"
	return
}

//返回多个值
func method8() (name1 string, name2 string, name3 string) {
	name1 = "a"
	name2 = "b"
	name3 = "c"
	return
}

//返回多个值 常用方法
func method9() (name1 string, name2 string, name3 string) {
	name1, name2, name3 = "a", "b", "c"
	return
}
func main() {
	//method1()
	//fmt.Println(method7())
	mina, maxa := getMinAndMax(10, 5, -1, 2, 1, 4, 3, 20, -9, 6);
	fmt.Println(mina, maxa)
	//通过匿名变量丢掉不要的返回值
	minb, _ := getMinAndMax(10, 5, -1, 2, 1, 4, 3, 20, -9, 6);
	fmt.Println(minb)

}

//2 3 1
func getMinAndMax(a ...int) (max int, min int) {
	min, max = a[0], a[0]
	for _, value := range a {
		if (value < min) {
			min = value
		}
		if (value > max) {
			max = value
		}
	}
	return
}
